package com.xpxrule.strategy.operator;

import com.xpxrule.constant.FieldType;
import com.xpxrule.dataobject.base.Range;
import com.xpxrule.dataobject.bo.RuleConditionItemBo;
import com.xpxrule.strategy.field.FieldTypeStrategy;

import java.util.List;
import java.util.Map;

public class BetweenOperatorStrategy extends OperatorStrategy{
    @Override
    String getAviatorExpressionByCollectionValue(String fieldKey, List<Object> listValue, RuleConditionItemBo conditionItemBo, Map<String, Object> params, FieldTypeStrategy fieldTypeStrategy, FieldType fieldType) {
        return null;
    }

    @Override
    String getAviatorExpressionByRangeValue(String fieldKey, Range<Object> rangeValue, RuleConditionItemBo conditionItemBo, Map<String, Object> params, FieldTypeStrategy fieldTypeStrategy, FieldType fieldType) {
        if (fieldType == FieldType.BIG_DECIMAL) {
            return String.format("(bigDecimalGreaterThan(%s, %s) && bigDecimalLessThan(%s, %s))", fieldKey, rangeValue.getBegin(), fieldKey, rangeValue.getEnd());
        }
        return String.format("(%s > %s && %s < %s)", fieldKey, rangeValue.getBegin(), fieldKey, rangeValue.getEnd());
    }

    @Override
    String getAviatorExpressionBySingleValue(String fieldKey, Object left, Object right, FieldType fieldType) {
        return "";
    }
}
